<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>商城测试</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <style>
      input{border: 1px solid #000;padding: 5px 10px;margin: 5px;border-radius: 5px;}
  	</style>
</head>
<body>
  <input onclick="get_contacts()" value="获取通讯录好友" type="button"/>
  <input onclick="wx_share('timeline')" value="微信朋友圈分享"  type="button"/>
  <input onclick="wx_share('session')" value="微信会话分享"  type="button"/>
  <input onclick="wx_pay()" value="微信支付"  type="button"/>
  <label id="deviceid">123</label>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript">
  var wx , contacts , wxPay;
  apiready = function(){
    wx = api.require('wx');
    contacts = api.require('contacts');
    wxPay = api.require('wxPay');

    var id = api.deviceId;//设备id
    var text=$api.byId('deviceid')
    $api.html(text,'设备id:'+id);
  };

  function get_contacts(){
    contacts.queryByPage({
       pageIndex: 0
    }, function(ret, err) {
       if (ret) {
         alert(JSON.stringify(ret));
       } else {
         alert(JSON.stringify(err));
       }
    });
  }

  function wx_share(scene){
    wx.shareWebpage({
      apiKey: 'wxd0d84bbf23b4a0e4',//从微信开放平台获取的 appid
      scene: scene,
      title: '测试标题',
      description: '分享内容的描述',
      thumb: 'widget://0.png',
      contentUrl: 'https://m.baidu.com'
    }, function(ret, err) {
      if (ret.status) {
        alert('分享成功');
      } else {
        alert(JSON.stringify(err));
      }
    });
  }

  function wx_pay(){
    wxPay.config( {
      apiKey: 'wx8d102283ae3ee327',
      mchId: '1505497871',
      partnerKey: '313bb53ec56a7b5fbe9e3d2d05a12470',
      notifyUrl: 'ret.notify_url'
    }, function(ret, err){
      if(ret.status){
        wxPay.pay({
          description: 'iPad mini 16G 白色',
          totalFee: '888',
          tradeNo: '1217752501201407033233368018',
          spbillCreateIP: '196.168.1.1',
          deviceInfo: '013467007045764',
          detail: 'iPad mini 16G 白色',
          attach: '说明',
          feeType: 'CNY',
          timeStart: '20091225091010',
          timeExpire: '20091227091010',
          goodsTag: 'WXG',
          productId: '12235413214070356458058',
          openId: 'oUpF8uMuAJO_M2pxb1Q9zNjWeS6o'
        },function(ret, err){
          if (ret.status) {
              alert(ret.result);
          } else {
              alert(JSON.stringify(err));
          }
        });
      }else{
        alert(JSON.stringify(ret));
      }
    });
  }
</script>
</html>
